feat: Add GITHUB_ACTION_MODE support for posting PR comments in GitHu…#923
feat: Add GITHUB_ACTION_MODE support for posting PR comments in GitHu…#923ctbui wants to merge 6 commits intogithub:main-enterprisefrom
Conversation
…b Actions - Add GITHUB_ACTION_MODE, GITHUB_REPOSITORY, and GITHUB_REF environment variables - Enable posting PR comments using GitHub Actions built-in env vars when running in action mode - Extract summary generation outside CREATE_PR_COMMENT condition for reuse
There was a problem hiding this comment.
Pull request overview
This PR adds a GITHUB_ACTION_MODE feature that allows safe-settings to post PR comments using GitHub Actions' built-in environment variables (GITHUB_REPOSITORY, GITHUB_REF) instead of relying on the existing CREATE_PR_COMMENT + check-suite payload flow.
Changes:
- Adds
GITHUB_ACTION_MODE,GITHUB_REPOSITORY, andGITHUB_REFtolib/env.js - Extracts the summary template outside the
CREATE_PR_COMMENTconditional block and adds a new code path inhandleResultsthat posts PR comments using GitHub Actions env vars - Documents the new action mode in
docs/github-action.md
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/env.js | Adds three new environment variable declarations for GitHub Action mode |
| lib/settings.js | Moves summary generation before conditionals; adds GITHUB_ACTION_MODE branch to post PR comments via Actions env vars |
| docs/github-action.md | Documents the new GITHUB_ACTION_MODE feature and adds it to the example workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a GITHUB_ACTION_MODE feature that allows safe-settings to post PR comments using GitHub Actions built-in environment variables (GITHUB_REPOSITORY, GITHUB_REF) instead of relying on the existing CREATE_PR_COMMENT + check suite payload approach.
Changes:
- Added
GITHUB_ACTION_MODE,GITHUB_REPOSITORY, andGITHUB_REFtolib/env.js - Added logic in
lib/settings.jsto post PR comments via GitHub Actions env vars whenGITHUB_ACTION_MODEis enabled, extracting the summary generation outside theCREATE_PR_COMMENTconditional - Added documentation for the new GitHub Action Mode in
docs/github-action.md
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/env.js | Adds three new environment variables for GitHub Action mode |
| lib/settings.js | Extracts summary outside CREATE_PR_COMMENT block; adds new code path to post PR comments using GHA env vars |
| docs/github-action.md | Documents the new GITHUB_ACTION_MODE feature and adds example env var to workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| this.log.warn | ||
| ? this.log.warn(`GITHUB_ACTION_MODE is set but GITHUB_REF ('${env.GITHUB_REF}') does not reference a pull request; skipping PR comment and continuing to complete check run.`) | ||
| : this.log.info(`GITHUB_ACTION_MODE is set but GITHUB_REF ('${env.GITHUB_REF}') does not reference a pull request; skipping PR comment and continuing to complete check run.`) |
| GITHUB_ACTION_MODE: process.env.GITHUB_ACTION_MODE === 'true', | ||
| // GitHub Actions built-in variables | ||
| GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || '', // format: owner/repo | ||
| GITHUB_REF: process.env.GITHUB_REF || '', // format: refs/pull/123/merge for PRs |
lib/settings.js
Outdated
| } catch (e) { | ||
| this.log.error(`Failed to post PR comment: ${e.message}`) | ||
| } | ||
| return |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a GITHUB_ACTION_MODE feature that enables safe-settings to post PR comments using GitHub Actions built-in environment variables (GITHUB_REPOSITORY and GITHUB_REF) instead of relying on the existing CREATE_PR_COMMENT mechanism tied to check suite payloads.
Changes:
- Adds
GITHUB_ACTION_MODE,GITHUB_REPOSITORY, andGITHUB_REFenvironment variables inlib/env.js - Extracts the summary generation outside the
CREATE_PR_COMMENTconditional block and adds new logic to post PR comments when running in GitHub Action mode - Adds documentation for the new GitHub Action Mode feature
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/env.js | Adds three new environment variables for GitHub Action mode |
| lib/settings.js | Moves summary generation before the conditional, adds GITHUB_ACTION_MODE branch to post PR comments via Actions env vars |
| docs/github-action.md | Documents the new GITHUB_ACTION_MODE feature and adds it to the example workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| GITHUB_ACTION_MODE: process.env.GITHUB_ACTION_MODE === 'true', | ||
| // GitHub Actions built-in variables | ||
| GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || '', // format: owner/repo | ||
| GITHUB_REF: process.env.GITHUB_REF || '', // format: refs/pull/123/merge for PRs |
| # Enable GitHub Action mode to post PR comments using built-in env vars | ||
| # GITHUB_REPOSITORY and GITHUB_REF are automatically injected by GitHub Actions | ||
| GITHUB_ACTION_MODE: true |
| this.log.warn | ||
| ? this.log.warn(`GITHUB_ACTION_MODE is set but GITHUB_REF ('${env.GITHUB_REF}') does not reference a pull request; skipping PR comment and continuing to complete check run.`) | ||
| : this.log.info(`GITHUB_ACTION_MODE is set but GITHUB_REF ('${env.GITHUB_REF}') does not reference a pull request; skipping PR comment and continuing to complete check run.`) | ||
| } | ||
| } else if (env.GITHUB_ACTION_MODE && (!env.GITHUB_REPOSITORY || !env.GITHUB_REF)) { | ||
| const missingVars = [ | ||
| !env.GITHUB_REPOSITORY && 'GITHUB_REPOSITORY', | ||
| !env.GITHUB_REF && 'GITHUB_REF' | ||
| ].filter(Boolean).join(' and ') | ||
| const message = `GITHUB_ACTION_MODE is set but required environment variable(s) ${missingVars} are missing or empty; skipping PR comment and continuing to complete check run.` | ||
| this.log.warn ? this.log.warn(message) : this.log.info(message) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a GITHUB_ACTION_MODE feature that allows safe-settings to post PR comments using GitHub Actions built-in environment variables (GITHUB_REPOSITORY, GITHUB_REF) instead of relying solely on the existing CREATE_PR_COMMENT + check_suite payload path.
Changes:
- Added three new environment variables (
GITHUB_ACTION_MODE,GITHUB_REPOSITORY,GITHUB_REF) tolib/env.js - Extracted the
summarytemplate outside theCREATE_PR_COMMENTconditional inlib/settings.jsand added new logic to post PR comments whenGITHUB_ACTION_MODEis enabled - Added documentation for the GitHub Action Mode feature
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/env.js | Adds GITHUB_ACTION_MODE (boolean), GITHUB_REPOSITORY, and GITHUB_REF env vars |
| lib/settings.js | Extracts summary generation, adds GITHUB_ACTION_MODE comment-posting logic with error handling |
| docs/github-action.md | Documents the new GitHub Action Mode and adds config to example workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| this.log.warn | ||
| ? this.log.warn(`GITHUB_ACTION_MODE is set but GITHUB_REF ('${env.GITHUB_REF}') does not reference a pull request; skipping PR comment and continuing to complete check run.`) | ||
| : this.log.info(`GITHUB_ACTION_MODE is set but GITHUB_REF ('${env.GITHUB_REF}') does not reference a pull request; skipping PR comment and continuing to complete check run.`) |
| # Enable GitHub Action mode to post PR comments using built-in env vars | ||
| # GITHUB_REPOSITORY and GITHUB_REF are automatically injected by GitHub Actions |
| GITHUB_ACTION_MODE: process.env.GITHUB_ACTION_MODE === 'true', | ||
| // GitHub Actions built-in variables | ||
| GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || '', // format: owner/repo | ||
| GITHUB_REF: process.env.GITHUB_REF || '', // format: refs/pull/123/merge for PRs |
…b Actions